﻿<%@ page language="C#" autoeventwireup="true" inherits="start_learn" CodeFile="~/LmsWebSite/start_learn.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>

		<script src="AjaxSupport.js" type="text/javascript"></script>
        <script src="standard.js" type="text/javascript"></script>
		<script src="SCORM_support/scorm_support.js"></script>
		<script type="text/javascript" language="JavaScript">
		    // set document.domain property here, if it works for your environment/SCORM implementation
		    // document.domain="";
		    var g_intAPIType = 0;
		    // Hook for Internet Explorer
		    if ((navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) || g_intAPIType == -1) {
		        g_intAPIType = 0;
		        document.write('<script language=\"VBScript\"\>\n');
		        document.write('On Error Resume Next\n');
		        document.write('Sub Captivate_FSCommand(ByVal command, ByVal args)\n');
		        document.write('Call Captivate_DoFSCommand(command, args)\n');
		        document.write('End Sub\n');
		        document.write('</script\>\n');
		        document.write('<script language=\"VBScript\"\>\n');
		        document.write('On Error Resume Next\n');
		        document.write('Sub Captivate_DoExternalInterface(ByVal command, ByVal parameter, ByVal value, ByVal variable)\n');
		        document.write('Call Captivate_DoExternalInterface(command, parameter, value, variable)\n');
		        document.write('End Sub\n');
		        document.write('</script\>\n');
		    } else {
		        g_intAPIType = 1;
		    }
		    var strURLFile = '<%# mobjRegisteredCourses.objCourses.CaptivateFile  %>'; 		// Name of the flash file
		    var intIntervalSecs = 1; 			// Number of seconds to wait for SCORM API to load
		    var g_intAPIOrder = 0; 				// Way to search for API object (0 - starts with bottom up; 1 - starts top down)
		    var strURLBase = "";
		    var strURLParams = "";
		    var strURLFull = document.location + "";
		    var intTemp = strURLFull.indexOf("#");
		    if (intTemp == -1)
		        intTemp = strURLFull.indexOf("?");
		    if (intTemp > 0)
		        strURLParams = strURLFull.substring(intTemp + 1, strURLFull.length);
		    var strTemp = location.protocol.toUpperCase();
		    if (strTemp.indexOf("FILE") == -1)
		        var intTemp = location.pathname.lastIndexOf("/");
		    else
		        var intTemp = location.pathname.lastIndexOf("\\");
		    if (intTemp != -1)
		        strURLBase = location.protocol + "//" + location.host + location.pathname.substring(0, intTemp + 1);
		    else
		        strURLBase = location.protocol + "//" + location.host + location.pathname;

		    strURLParams = (strURLParams == unescape(strURLParams) ? escape(strURLParams) : strURLParams);
		    strURLParams = (strURLParams == "" ? "" : "?") + strURLParams;

		    function Finish() {

		        if ((isAPI()) && (g_bFinishDone == false)) {
		            (g_zAPIVersion == "0.2" ? g_objAPI.LMSCommit("") : g_objAPI.Commit(""));
		            g_bFinishDone = (g_zAPIVersion == "0.2" ? g_objAPI.LMSFinish("") == "true" : g_objAPI.Terminate("") == "true");
		        }
		        return (g_bFinishDone + "") // Force type to string
		    }

		    if (g_intAPIType == 0) {
		        // Detect Internet Explorer
		        var g_bIsInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

		        // Handle fscommand messages from a Flash movie
		        function Captivate_DoFSCommand(command, args) {



		            var CaptivateObj;
		            try {
		                CaptivateObj = g_bIsInternetExplorer ? Captivate : document.Captivate;
		            }
		            catch (ex) { }

		            var strFSArgs = new String(args);
		            var strFSCmd = new String(command);
		            var strErr = "true";
		            var strFSArg1, strFSArg2, strFSArg3
		            var intFSDelimiter = strFSArgs.indexOf("|");
		            if (intFSDelimiter > -1) {
		                strFSArg1 = strFSArgs.substr(0, intFSDelimiter); 	// Name of data element to get from API
		                var strFSTemp = strFSArgs.substr(intFSDelimiter + 1);
		                intFSDelimiter = strFSTemp.indexOf("|");
		                if (intFSDelimiter > -1) {
		                    strFSArg2 = strFSTemp.substr(0, intFSDelimiter); // Value
		                    strFSArg3 = strFSTemp.substr(intFSDelimiter + 1); // Variable
		                } else {
		                    strFSArg2 = strFSTemp;
		                }
		            } else {
		                strFSArg1 = strFSArgs;
		            }

		            // do nothing, if SCORM API is not available
		            if (!isAPI()) return;

		            if (strFSCmd == "LMSInitialize" || strFSCmd == "Initialize") {
		                CaptivateObj.SetVariable(strFSArg3, eval('g_objAPI.' + strFSCmd + '(\"\");'));
		            } else if (strFSCmd == "LMSSetValue" || strFSCmd == "SetValue") {
		                strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\",\"' + strFSArg2 + '\");');
		                CaptivateObj.SetVariable(strFSArg3, strErr);
		            } else if (strFSCmd == "LMSFinish" || strFSCmd == "Terminate") {
		                g_bFinishDone = eval('g_objAPI.' + strFSCmd + '(\"\");')
		                strErr = g_bFinishDone;
		                CaptivateObj.SetVariable(strFSArg3, g_bFinishDone);
		            } else if (strFSCmd == "LMSCommit" || strFSCmd == "Commit") {
		                strErr = eval('g_objAPI.' + strFSCmd + '(\"\");');
		                CaptivateObj.SetVariable(strFSArg3, strErr);
		            } else if ((strFSArg2) && (strFSArg2.length > 0)) {
		                if (strFSCmd == "LMSGetLastError") {
		                    strErr = eval('g_objAPI.' + strFSCmd + '();')
		                    CaptivateObj.SetVariable(strFSArg3, strErr);
		                } else {
		                    strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\");')
		                    CaptivateObj.SetVariable(strFSArg3, strErr);
		                }
		            } else if (strFSCmd.substring(0, 3) == "LMSGet") {
		                strErr = "-2: No Flash variable specified"
		            }

		            return strErr;
		        }
		        function Captivate_DoExternalInterface(command, parameter, value, variable) {
		            var CaptivateObj;
		            try {
		                CaptivateObj = g_bIsInternetExplorer ? Captivate : document.Captivate;
		            }
		            catch (ex) { }
		            //alert("command  " + command + " ;parameter " +parameter+ " ;value " + value + " ;variable " + variable );
		            //var strFSArgs = new String(args);
		            var strFSCmd = new String(command);
		            var strErr = "true";

		            var strFSArg1, strFSArg2, strFSArg3;

		            strFSArg1 = parameter;
		            strFSArg2 = value;
		            strFSArg3 = variable;
		            /*var intFSDelimiter = strFSArgs.indexOf("|");
		            if (intFSDelimiter > -1)
		            {
		            strFSArg1 = strFSArgs.substr(0, intFSDelimiter); 	// Name of data element to get from API
		            var strFSTemp = strFSArgs.substr(intFSDelimiter + 1);
		            intFSDelimiter = strFSTemp.indexOf("|");
		            if(intFSDelimiter > -1)
		            {
		            strFSArg2 = strFSTemp.substr(0, intFSDelimiter);	// Value
		            strFSArg3 = strFSTemp.substr(intFSDelimiter + 1);	// Variable
		            } else {
		            strFSArg2 = strFSTemp;
		            }
		            } else {
		            strFSArg1 = strFSArgs;
		            }*/

		            // do nothing, if SCORM API is not available
		            if (!isAPI()) return;

		            if (strFSCmd == "LMSInitialize" || strFSCmd == "Initialize") {
		                //CaptivateObj.SetVariable(strFSArg3, eval('g_objAPI.' + strFSCmd + '(\"\");'));
		                CaptivateObj.SetScormVariable(strFSArg3, eval('g_objAPI.' + strFSCmd + '(\"\");'));

		            } else if (strFSCmd == "LMSSetValue" || strFSCmd == "SetValue") {
		                strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\",\"' + strFSArg2 + '\");');
		                //CaptivateObj.SetVariable(strFSArg3, strErr);
		                CaptivateObj.SetScormVariable(strFSArg3, strErr);

		            } else if (strFSCmd == "LMSFinish" || strFSCmd == "Terminate") {
		                g_bFinishDone = eval('g_objAPI.' + strFSCmd + '(\"\");')
		                strErr = g_bFinishDone;
		                //CaptivateObj.SetVariable(strFSArg3, g_bFinishDone);
		                CaptivateObj.SetScormVariable(strFSArg3, g_bFinishDone);

		            } else if (strFSCmd == "LMSCommit" || strFSCmd == "Commit") {
		                strErr = eval('g_objAPI.' + strFSCmd + '(\"\");');
		                //CaptivateObj.SetVariable(strFSArg3, strErr);
		                CaptivateObj.SetScormVariable(strFSArg3, strErr);

		            } else if ((strFSArg2) && (strFSArg2.length > 0)) {
		                if (strFSCmd == "LMSGetLastError") {
		                    strErr = eval('g_objAPI.' + strFSCmd + '();')
		                    //CaptivateObj.SetVariable(strFSArg3, strErr);
		                    CaptivateObj.SetScormVariable(strFSArg3, strErr);

		                } else {
		                    strErr = eval('g_objAPI.' + strFSCmd + '(\"' + strFSArg1 + '\");')
		                    //CaptivateObj.SetVariable(strFSArg3, strErr);
		                    CaptivateObj.SetScormVariable(strFSArg3, strErr);

		                }
		            } else if (strFSCmd.substring(0, 3) == "LMSGet") {
		                strErr = "-2: No Flash variable specified"
		            }

		            return strErr;
		        }
		    }

		</script>
        
        
        <script type="text/javascript">

        var bIsLoaded = false;

        var bCheckLoaded = false;



            var RegisteredCourses = 
            {
                CurrentData : '<%# mobjRegisteredCourses.CurrentData %>',
                CoursesID : <%# mobjRegisteredCourses.CoursesID %>,
                TotalSlides : -1  ,
                LastSlide : <%# mobjRegisteredCourses.LastSlide %>,
                TotalSpendTime : <%# mobjRegisteredCourses.TotalSpendTime %> 
                
                
            };


            var myXml = null;
            var bReturned = true;
            var xmlTime = -1;

            function largeTick()
            {
                
               setTimeout (largeTick,10000);
                
                if (!bReturned)
                    return;

                    
                myXml = new ajaxRequest ();
                                             
                bReturned = false;
                xmlTime = 0;

                try
                {
                    if (myXml == false)
                    {
                        window.location="./loginen.aspx";
                    }
                }
                catch (ex)
                {
                    
                }

                myXml.onreadystatechange=function(){
                    if (myXml.readyState==4){
                        if (myXml.status==200){
                            
                            xmlTime = -1;
                            bReturned = true;
                            if (myXml.responseText.indexOf ("false") != -1)
                            {
                                alert (myXml.responseText);
                                // server error no login user found
                                window.location="./loginen.aspx";
                            }
                            
                        }
                        else
                        {
                            //client error , no internet connection
                            window.location="./loginen.aspx";

                        }
                    }
                    
                }


                myXml.open("POST","./addRegCourseData.ashx",true);


                //var currentTime = ((new Date()).getTime() - startTime)/1000;

                //currentTime = Math.floor (currentTime);


                var TotalSpendTime = 0;//RegisteredCourses.TotalSpendTime + currentTime;

                //alert(TotalSpendTime);


                var params = "CoursesID=" + RegisteredCourses.CoursesID.toString() + "&TotalSlides=" + RegisteredCourses.TotalSlides.toString() +
                  "&LastSlide=" + RegisteredCourses.LastSlide.toString() + "&TotalSpendTime=" + TotalSpendTime.toString() + "&CurrentData=" + RegisteredCourses.CurrentData.toString();

                //alert (params);

                myXml.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

                myXml.send (params);

                


            }


            
            function smallTick()
            {
                setTimeout (smallTick,200);
                
                if (!bReturned)
                {
                    xmlTime ++;

                    if (xmlTime > 200)
                    {
                        window.location = "./loginen.aspx";
                        
                    }
                }


                if (RegisteredCourses.CurrentData == '')
                    RegisteredCourses.CurrentData = '0';
                

                
                
                var arr = RegisteredCourses.CurrentData.split(';');

                
                

                var g_bIsInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
                var CaptivateObj = null;            
                try
                {
                     CaptivateObj = g_bIsInternetExplorer ? Captivate : document.Captivate;
                }
                catch (ex)
                {
                    CaptivateObj = document.Captivate;
                }


                RegisteredCourses.LastSlide = CaptivateObj.GetVariable('rdinfoCurrentSlide');
                var bFound = false;

                for (var i=0;i<arr.length;i++)
                {
                    if (arr[i] == RegisteredCourses.LastSlide.toString())
                    {
                        bFound = true;
                        break;
                    }
                }

                if (!bFound)
                    arr.push (RegisteredCourses.LastSlide.toString());

                var data = '';
                for (var i=0;i<arr.length;i++)
                {
                    if (i == 0)
                        data += arr[i];
                    else
                        data += ';' + arr[i];
                }

                
                RegisteredCourses.CurrentData = data;

                if (RegisteredCourses.LastSlide == (RegisteredCourses.TotalSlides-1))
                {
                    largeTick();
                }
                


            }
            
            
           
            

            function ab() {
                
                
                if ((!bIsLoaded) && (!bCheckLoaded))
                   checkLoaded();

                if (!bIsLoaded)
                {
                    setTimeout (ab,2000);
                    return;
                }

                


                var g_bIsInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
                var CaptivateObj = null;            
                try
                {
                     CaptivateObj = g_bIsInternetExplorer ? Captivate : document.Captivate;
                }
                catch (ex)
                {
                    CaptivateObj = document.Captivate;
                }
                //var a = CaptivateObj.GetVariable('NoOfTOCEntries');
                //var b = CaptivateObj.GetVariable('tocInitDone');
                




                if (RegisteredCourses.LastSlide == "")
                    RegisteredCourses.LastSlide = 0;
               if (RegisteredCourses.LastSlide <= 0)
                    RegisteredCourses.LastSlide = 0;
                



                RegisteredCourses.TotalSlides = CaptivateObj.GetVariable('rdinfoSlideCount');

                

                CaptivateObj.SetVariable('cpCmndGotoSlide', RegisteredCourses.LastSlide.toString());
                CaptivateObj.SetVariable('rdcmndResume', '1');
                
                var d = CaptivateObj.GetVariable('rdinfoCurrentSlide');

                
                if (d.toString() != RegisteredCourses.LastSlide.toString())
                {
                    setTimeout (ab,1000);
                    return;
                }

                //alert (RegisteredCourses.LastSlide.toString());
                //alert (RegisteredCourses.TotalSlides.toString());


//                if (d == RegisteredCourses.LastSlide) {
                   // alert(d + '/' + RegisteredCourses.TotalSlides);


                   

                   smallTick();
                   largeTick();
                   
                   
//                }

//                else {
//                    setTimeout(ab, 10000);
//                }
            }


            function abStart() {
                //var firstDate = new Date();
                //startTime = firstDate.getTime();

                //setTimeout(ab, 1000);

                ab();
            }



            function checkLoaded ()
            {
                bCheckLoaded = true;
            try
            {
//                if (RegisteredCourses.LastSlide == "")
//                    RegisteredCourses.LastSlide = 1;
//                if (RegisteredCourses.LastSlide <= 0)
//                    RegisteredCourses.LastSlide = 1;


                 var g_bIsInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
                var CaptivateObj = null;            
                try
                {
                     CaptivateObj = g_bIsInternetExplorer ? Captivate : document.Captivate;
                }
                catch (ex)
                {
                    CaptivateObj = document.Captivate;
                }

                 RegisteredCourses.TotalSlides = CaptivateObj.GetVariable('rdinfoSlideCount');
                
                CaptivateObj.SetVariable('cpCmndGotoSlide', (RegisteredCourses.TotalSlides-1).toString());
                CaptivateObj.SetVariable('rdcmndResume', '1');
                
                
                var d = CaptivateObj.GetVariable('rdinfoCurrentSlide');

                if (d.toString() == (RegisteredCourses.TotalSlides-1).toString())
                {
                    bIsLoaded = true;
                }
                else
                {
                    bIsLoaded = false;

                    setTimeout (checkLoaded,1000);

                }
                }

                catch (Error)
                {
                     bIsLoaded = false;

                    setTimeout (checkLoaded,1000);
                }



            }
			



            function FinishAll()
            {
                try
                {
                    largeTick();
                }
                catch(err)
                {
                }

                
                
                
            }


            


			
        </script>
</head>
<body bgcolor="#F5F4F1" onunload="Finish();">
    <form id="form1" runat="server">
    <div>
         <center>
		<div id="CaptivateContent">&nbsp;
		</div>
		<layer id="NS_dynamic" name="NS_dynamic">
		<script type="text/javascript">
		    var tempso = new SWFObject("SCORM_support/scorm_support.swf", "scorm_support", "2", "2", "10", "#CCCCCC");
		    tempso.addParam("quality", "high");
		    tempso.addParam("id", "scorm_support");
		    tempso.addParam("bgcolor", "#FFFFFF");
		    tempso.addParam("menu", "false");
		    tempso.addParam("movie", "SCORM_support/scorm_support.swf");
		    tempso.setAttribute("redirectUrl", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
		</script>
		<noscript>
			<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
				codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"
				width="2" height="2" id="scorm_support" align="">
				<param name=movie value="SCORM_support/scorm_support.swf"> <param name=quality value=high> <param name=menu value=false> <param name=bgcolor value=#FFFFFF>
				<embed src="SCORM_support/scorm_support.swf" quality=high bgcolor=#FFFFFF  width="2" height="2" name="scorm_support" align=""
					type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer">
				</embed>
			</object>
		</noscript>
		</layer>
		<script type="text/javascript" language="JavaScript">
		    var timeCurrent_int = new Date().getTime();
		    var timeLimit_int = new Date().getTime() + (intIntervalSecs * 1000);
		    // This simply loops for a set period of time, waiting for the API to
		    // load and/or be found.  A better solution would be to use setInterval
		    // and on the timeout, redirect or load the resulting Captivate file.
		    while ((g_objAPI == null) && timeCurrent_int < timeLimit_int) {
		        g_objAPI = getAPI(g_intAPIOrder);
		        timeCurrent_int = new Date().getTime();
		    }
		    if (g_objAPI != null) {
		        strURLParams += (strURLParams == "" ? "?" : "&") + "SCORM_API=" + g_zAPIVersion + "&SCORM_TYPE=" + g_intAPIType;
		    }

		    document.write('<center>');
		    document.write('<table border="0" cellpadding="7" cellspacing="7"> \n');
		    document.write('  <tr>  \n');
		    document.write('    <td align="middle">');

		    var so = new SWFObject(strURLFile + strURLParams, "Captivate", "1063", "647", "10", "#CCCCCC");
		    so.addParam("quality", "high");
		    so.addParam("name", "Captivate");
		    so.addParam("id", "Captivate");
		    so.addParam("wmode", "window");
		    so.addParam("bgcolor", "#F5F4F1");
		    so.addParam("menu", "false");
		    so.addVariable("variable1", "value1");
		    so.setAttribute("redirectUrl", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
		    so.write("CaptivateContent");

		    document.write('</td> \n');
		    document.write('  </tr> \n');
		    document.write('</table> \n');
		    document.write('</center>');
		</script>
		<script type="text/javascript">
		    try {
		        document.getElementById('Captivate').focus();
		    } catch (ex) { }
		    try {
		        document.Captivate.focus();
		    } catch (ex) { }

		    abStart();
		</script>


		

		</center>
    </div>
    </form>
</body>
</html>
